home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - Mac PPC / demos / cat / cat.dylan next >
Encoding:
Text File  |  1995-03-15  |  2.2 KB  |  77 lines  |  [TEXT/MPCC]

  1. module: Concatenate
  2. rcs-header: $Header: cat.dylan,v 1.2 94/10/26 19:46:02 nkramer Exp $
  3.  
  4. //======================================================================
  5. //
  6. // Copyright (c) 1994  Carnegie Mellon University
  7. // All rights reserved.
  8. // 
  9. // Use and copying of this software and preparation of derivative
  10. // works based on this software are permitted, including commercial
  11. // use, provided that the following conditions are observed:
  12. // 
  13. // 1. This copyright notice must be retained in full on any copies
  14. //    and on appropriate parts of any derivative works.
  15. // 2. Documentation (paper or online) accompanying any system that
  16. //    incorporates this software, or any part of it, must acknowledge
  17. //    the contribution of the Gwydion Project at Carnegie Mellon
  18. //    University.
  19. // 
  20. // This software is made available "as is".  Neither the authors nor
  21. // Carnegie Mellon University make any warranty about the software,
  22. // its performance, or its conformity to any specification.
  23. // 
  24. // Bug reports, questions, comments, and suggestions should be sent by
  25. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  26. //
  27. //======================================================================
  28. //
  29. // This demo demonstrates the streams library by duplicating the unix
  30. // ``cat'' utility.
  31. //
  32. // We need to define our own library because we need to use the Streams
  33. // library in addition to the standard Dylan library.
  34. //
  35.  
  36. define library Concatenate
  37.   use Dylan;
  38.   use Streams;
  39. end;
  40.  
  41. define module Concatenate
  42.   use Dylan;
  43.   use Extensions;
  44.   use Streams;
  45.   use Standard-IO;
  46. end;
  47.  
  48. define method main (argv0, #rest names)
  49. //  break();
  50.   if (empty?(names))
  51.     spew(*standard-input*);
  52.   else
  53.     for (name in names)
  54.       let stream = if (name = "-")
  55.              make(<fd-stream>, fd: 0);
  56.            else
  57.              make(<file-stream>, name: name);
  58.            end;
  59.       spew(stream);
  60.       close(stream);
  61.     end;
  62.   end;
  63. end;
  64.  
  65. define method spew (stream :: <stream>)
  66.   let (buf, next, stop) = get-input-buffer(stream);
  67.   if (next ~= stop)
  68.     write(buf, *standard-output*, start: next, end: stop);
  69.   end;
  70.   for (stop = fill-input-buffer(stream, 0)
  71.      then fill-input-buffer(stream, 0),
  72.        until stop = 0)
  73.     write(buf, *standard-output*, start: 0, end: stop);
  74.   end;
  75.   release-input-buffer(stream, 0, 0);
  76. end;
  77.